from sqlalchemy import *
from sqlalchemy.sql import select
from sqlalchemy.schema import *

class oracleUtility:
	def __init__(self, connA, connB):
		self.connStringA = connA
		self.connStringB = connB
		self.db_engine_A = create_engine(connA, echo=False)
		self.db_engine_B = create_engine(connB, echo=False)
		self.metaA = MetaData(self.db_engine_A)
		self.metaB = MetaData(self.db_engine_B)

	def dataA2B(self, tableName):
		tblA = Table(tableName, self.metaA, autoload=True, autoload_with=self.db_engine_A)
		tblB = Table(tableName, self.metaB, autoload=True, autoload_with=self.db_engine_B)
		
		tblA.c.keys()
		tblB.c.keys()
		
		connA = self.db_engine_A.connect()
		connB = self.db_engine_B.connect()

		# query = select([tblTester]).where(tblTester.c.id==6) # 提供查询条件
		query = select([tblA])  
		result = connA.execute(query)

		try:
			rowCount = 0
			for row in result:
				# print(row)
				# users_table.insert().execute(name="sss", email="eee@eee.com")
				tblB.insert().execute(row)
				rowCount = rowCount + 1
				# print('insert one row')
				# row[t.c.id],row[t.c.name] 

			result.close()
			print("{0} row count:{1}".format(tableName, rowCount))
		except Exception as ex:
			result.close()
			print(ex)
    

